package service.impl;

import dao.AccountDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import service.AccountService;

import javax.annotation.Resource;

@Service("accountService")
public class AccountServiceImpl implements AccountService {
    @Resource(name = "accountDao")
    private AccountDao accountDao;

    /**
     * 转账方法(切点)，通过配置文件增强
     * @param outMan 转出用户
     * @param inMan 转入用户
     * @param money 金额
     */
    public void transfer(String outMan, String inMan, double money) {
        accountDao.out(outMan,money);
        int i = 1/0;//人工制造一个异常
        accountDao.in(inMan,money);
    }

    /**
     * 转账方法(切点)，通过注解方式增强
     * @param outMan 转出用户
     * @param inMan 转入用户
     * @param money 金额
     * - isolation:事务的隔离级别
     * - propagation：事务的传播行为
     * - timeout：超时时间
     * - read-only：是否只读
     */
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED)
    public void transferByAnno(String outMan, String inMan, double money) {
        accountDao.out(outMan,money);
        int i = 1/0;//人工制造一个异常
        accountDao.in(inMan,money);
    }
}
